﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Default3 : System.Web.UI.Page
{
    string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["xxnewsConnectionString"].ConnectionString;
    SqlConnection sqlcon;
    SqlCommand sqlcom;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["pn"] == "" || Session["pn"] == null)
        {
            Response.Redirect("default.aspx?lb=审批");
        }
        if (Session["pngeren"] == "" || Session["pngeren"] == null)
        {
            Response.Redirect("default.aspx?lb=审批");
        }
        if (Session["pn"].ToString().Contains("材料科") == false)
        {
            Response.Redirect("default.aspx?lb=审批");
        }
        Label1.Text = Session["pn"].ToString();
        Label2.Text = Session["pngeren"].ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {

                string txt1 = ((TextBox)GridView1.Rows[i].Cells[8].FindControl("TextBox2")).Text;
                if (txt1.Length == 0)
                {
                    string jinggao1 = "<SCRIPT language=javascript>alert('";
                    jinggao1 += "请输入序号为 " + (GridView1.PageSize * GridView1.PageIndex + i + 1).ToString() + " 的材料目录价！";
                    jinggao1 += "');</SCRIPT>";
                    ClientScript.RegisterStartupScript(this.GetType(), "aa3", jinggao1);

                    //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "", jinggao1, true);
                    return;
                }
                if (txt1 == "0")
                {
                    string jinggao1 = "<SCRIPT language=javascript>alert('";
                    jinggao1 += "序号为 " + (GridView1.PageSize * GridView1.PageIndex + i + 1).ToString() + " 的材料目录价不能为0！";
                    jinggao1 += "');</SCRIPT>";
                    ClientScript.RegisterStartupScript(this.GetType(), "aa3", jinggao1);

                    //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "", jinggao1, true);
                    return;
                }
                if (!isnumber(txt1))
                {
                    string jinggao2 = "<SCRIPT language=javascript>alert('";
                    jinggao2 += "请在序号为 " + (GridView1.PageSize * GridView1.PageIndex + i + 1).ToString() + " 的材料目录价中输入数字！";
                    jinggao2 += "');</SCRIPT>";
                    ClientScript.RegisterStartupScript(this.GetType(), "aa3", jinggao2);

                    //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "", jinggao2, true);

                    return;

                }
                //for (int j = 0; j < txt1.Trim().Length; j++)
                //{
                //    char a;
                //    int k;
                //    a = Convert.ToChar(txt1.Substring(j, 1));
                //    k = (int)a;
                //    if (k < 48 || k > 57)
                //    //if ((k < 48 || k > 57) && k != 46)
                //    {
                //        string jinggao2 = "<SCRIPT language=javascript>alert('";
                //        jinggao2 += "请在序号为 " + (GridView1.PageSize * GridView1.PageIndex + i + 1).ToString() + " 的材料目录价中输入数字(整数)！";
                //        jinggao2 += "');</SCRIPT>";
                //        ClientScript.RegisterStartupScript(this.GetType(), "aa3", jinggao2);

                //        //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "", jinggao2, true);

                //        return;
                //    }
                //}
     
        }
        
        
        
        try
        {
            //更新明细表
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {

                int id = Convert.ToInt32(GridView1.Rows[i].Cells[1].Text);
                string cjsl = ((TextBox)GridView1.Rows[i].Cells[8].FindControl("TextBox2")).Text;
                string sqlstr = "update cailiaomingxi set danjia='" + cjsl + "' where id=" + id;
                //Response.Write(sqlstr);
                //Response.End();
                sqlcon = new SqlConnection(strCon);
                sqlcom = new SqlCommand(sqlstr, sqlcon);
                sqlcon.Open();
                sqlcom.ExecuteNonQuery();
                sqlcon.Close();
            }
            
            //更新管理表
            string sqlstr2 = "update cailiaoguanli set cailiaoname='" + Label2.Text + "',cailiaotime='" + DateTime.Now.ToString() + "',cailiaoip='" + Page.Request.UserHostAddress.ToString().Trim() + "',zt=5 where c_id=" + Request.QueryString["id"];
            //Response.Write(sqlstr2);
            //Response.End();
            sqlcon = new SqlConnection(strCon);
            sqlcom = new SqlCommand(sqlstr2, sqlcon);
            sqlcon.Open();
            sqlcom.ExecuteNonQuery();
            sqlcon.Close();

        }
        catch (SqlException)
        {
            throw;
        }

        string jinggao3 = "<SCRIPT language=javascript>alert('";
        jinggao3 += "受理操作成功！";
        jinggao3 += "');</SCRIPT>";
        ClientScript.RegisterStartupScript(this.GetType(), "aa3", jinggao3);
        ClientScript.RegisterStartupScript(this.GetType(), "aa4", "<SCRIPT language=javascript>document.location.href='clk_shoulilist.aspx';</SCRIPT>");

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#D1DDF1'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
        }
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = id.ToString();
            e.Row.Cells[6].Text = e.Row.Cells[6].Text.Replace("&amp;#215;", "×").Replace("&amp;quot;", "");
        }

    }
    private bool isnumber(string otext)
    {
        try
        {
            Double var1 = Convert.ToDouble(otext);
            return true;
        }
        catch
        {
            return false;
        }
    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            int id = e.Row.RowIndex + 1;
            e.Row.Cells[1].Text = id.ToString();
        }
    }
}